package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TPerson;
import com.ruoyi.system.service.ITPersonService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人员Controller
 * 
 * @author ruoyi
 * @date 2022-04-25
 */
@Controller
@RequestMapping("/system/person")
public class TPersonController extends BaseController
{
    private String prefix = "system/person";

    @Autowired
    private ITPersonService tPersonService;

    @RequiresPermissions("system:person:view")
    @GetMapping()
    public String person()
    {
        return prefix + "/person";
    }

    /**
     * 查询人员列表
     */
    @RequiresPermissions("system:person:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TPerson tPerson)
    {
        startPage();
        List<TPerson> list = tPersonService.selectTPersonList(tPerson);
        return getDataTable(list);
    }

    /**
     * 导出人员列表
     */
    @RequiresPermissions("system:person:export")
    @Log(title = "人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TPerson tPerson)
    {
        List<TPerson> list = tPersonService.selectTPersonList(tPerson);
        ExcelUtil<TPerson> util = new ExcelUtil<TPerson>(TPerson.class);
        return util.exportExcel(list, "人员数据");
    }

    /**
     * 新增人员
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存人员
     */
    @RequiresPermissions("system:person:add")
    @Log(title = "人员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TPerson tPerson)
    {
        return toAjax(tPersonService.insertTPerson(tPerson));
    }

    /**
     * 修改人员
     */
    @RequiresPermissions("system:person:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        TPerson tPerson = tPersonService.selectTPersonById(id);
        mmap.put("tPerson", tPerson);
        return prefix + "/edit";
    }

    /**
     * 修改保存人员
     */
    @RequiresPermissions("system:person:edit")
    @Log(title = "人员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TPerson tPerson)
    {
        return toAjax(tPersonService.updateTPerson(tPerson));
    }

    /**
     * 删除人员
     */
    @RequiresPermissions("system:person:remove")
    @Log(title = "人员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tPersonService.deleteTPersonByIds(ids));
    }

    /**
     * 查询字典详细
     */
    @GetMapping("/getTribute/{personId}")
    public String detail(@PathVariable("personId") String personId, ModelMap mmap)
    {
        mmap.put("personId",personId);
        return "tribute/list/list";
    }
}
